<%@ page contentType="text/html; charset=UTF-8" language="java"%>
<%@ page import="com.hzqy.commons.utils.ConstantUtils" %>
<%@ taglib prefix="limits" uri="/WEB-INF/tld/limits.tld"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>浙江数据开放接口管理</title>
<link rel="stylesheet" type="text/css"	href="../../static/js/themes/defalut.css">
<link rel="stylesheet" type="text/css"	href="../../static/js/themes/public.css">
<link rel="stylesheet" type="text/css"	href="../../static/js/themes/ddspstyle.css">
<link rel="stylesheet" type="text/css"	href="../../static/js/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"	href="../../static/js/themes/icon.css">
<link href="../../static/css/uploadify.css" rel="stylesheet" type="text/css"/>
<link rel="stylesheet" type="text/css"	href="../../static/js/WdatePicker/skin/WdatePicker.css">


<script type="text/javascript" src="../../static/js/jquery.min.js"></script>
<script type="text/javascript" src="../../static/js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="../../static/js/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="../../static/js/index.js"></script>
<script type="text/javascript" src="../../static/js/WdatePicker/WdatePicker.js"></script>
<script src="../../static/js/jquery.uploadify.js" type="text/javascript"></script>

<%
String []nonceObj=ConstantUtils.getNonceObject();
String f_path = request.getServletPath();
f_path = f_path.substring(1, f_path.lastIndexOf("/"));
%>

<script type="text/javascript">
		var queryParams;
		function EasyuiDatagrid() {
			$("#easyui-datagrid").datagrid({
				url: '../../industry/zjDataOpenInterface_list.do',
				nowrap: true,
				striped: true,
				border: false,
				fit: true,
				rownumbers:true,
				queryParams: getGueryParams(),
				columns: [[
					{field:'id',checkbox:true},
					{field:'f_zdoi_id',title:'ID',align:'center',width:50},
					{field:'f_zdoi_name',title:'接口名称',align:'center',width:150},
					{field:'f_zdoi_path',title:'接口地址',align:'center',width:150},
					{field:'f_zdoi_appsecret',title:'接口登录认证id',align:'center',width:220},
					{field:'f_zdoi_status',title:'状态',align:'center',width:50,
						formatter:function(value,row,index) {
							var status = "未知";
							if(value==1){
								status="有效";
							} else if(value==2){
								status="无效";
							}
							return status;
						}	
					},
					{field:'f_zdoi_accessed',title:'是否可被访问',align:'center',width:80,
						formatter:function(value,row,index) {
							var status = "未知";
							if(value==1){
								status="可被访问";
							} else if(value==2){
								status="不可被访问";
							}
							return status;
						}	
					},
					{field:'f_zdoi_limitcount',title:'数量',align:'center',width:50},
					{field:'f_zdoi_update',title:'更新时间',align:'center',width:150},
					{field:'f_zdoi_cdate',title:'创建时间',align:'center',width:150},
					{field:'_parentId',title:'操作',align:'center',width:350,
						formatter:function(value,row,index){
							str ="";
							<limits:uiAuth url="delete_zjDataOpenInterface.do">	
								str+= '<a class="easyui-linkbutton l-btn l-btn-plain" iconCls="icon-ok" href="javascript:void(0);" plain="true" onclick="onClickBtnDelete(\''+row.f_zdoi_id+'\');" ><span class="l-btn-left"><span class="l-btn-text icon-remove l-btn-icon-left">删除</span></span></a>';
							</limits:uiAuth>
							<limits:uiAuth url="update_zjDataOpenInterface.do">	
								str+= '<a class="easyui-linkbutton l-btn l-btn-plain" iconCls="icon-ok" href="javascript:void(0);" plain="true" onclick="edit(\''+row.f_zdoi_id+'\');" ><span class="l-btn-left"><span class="l-btn-text icon-edit l-btn-icon-left">修改</span></span></a>';
							</limits:uiAuth>
							<limits:uiAuth url="zjDataOpenInterfaceDatas_list.do">
								str+= '<a class="easyui-linkbutton l-btn l-btn-plain" iconCls="icon-ok" href="javascript:void(0);" plain="true" onclick="info(\''+row.f_zdoi_id+'\');" ><span class="l-btn-left"><span class="l-btn-text icon-search l-btn-icon-left">查看数据</span></span></a>';
							</limits:uiAuth>
							<limits:uiAuth url="insert_batch_zjDataOpenInterfaceDatas.do">
								str+= '<a class="easyui-linkbutton l-btn l-btn-plain" iconCls="icon-ok" href="javascript:void(0);" plain="true" onclick="batchAddZjDataOpenInterfaceDatas(\''+row.f_zdoi_id+'\');" ><span class="l-btn-left"><span class="l-btn-text icon-add l-btn-icon-left">批量导入该接口的数据</span></span></a>';
							</limits:uiAuth>
							return str;
						}
					}
				]],
				singleSelect:false,
				pagination:true,
				pageList:[10,20,30,40,50],
				pageSize:10,
				toolbar: '#toolbar',
				
				onExpandRow: function(index,row){
				
				},
				onSelect: function(rowIndex,rowData) {
					
				},
				onUnselect: function(rowIndex,rowData) {
					
				},
				onCheckAll: function(rowIndex,rowData) {
					
				},
				onUncheckAll: function(rowIndex,rowData) {
				
				},
				onLoadSuccess: function(data) {
					if(data.total==-1) {
						$.messager.defaults={ok:"确定",cancel:"取消"};
						$.messager.confirm('提示', '用户尚未登录,请登录', function(r){
						if (r){
						    window.parent.location.href='/login.do';
						    return false;
						}});
					}
				}
			});
		}
	
		onClickBtnDelete = function(id){
			$.messager.confirm('确定删除节目','确定删除节目么?',function(r){
				if(r){
					app_ajax('../../industry/delete_zjDataOpenInterface.do?f_zdoi_id='+id+'&stime=<%=nonceObj[0]%>&sign=<%=nonceObj[1]%>',
					'',
					function(msg){
						if(msg.success) {
							alert("删除成功!");
							if (checkAjaxRequestValidity(msg)) {
								gotoSearch($('#easyui-treegrid'));
							}
						} else {
							alert("删除异常，请联系管理员");
							if($.isFunction(window.showMessager)){
								window.showMessager(msg.resultTitle,msg.result);
							}
						}
						window.location.reload();
					}
					);
				}
			});
		};
		
		function getGueryParams(){
			return {
				f_zdoi_name:$("#f_zdoi_name").val(),
				f_zdoi_status:$("#f_zdoi_status").val(),
				f_zdoi_path:$("#f_zdoi_path").val(),
				f_zdoi_appsecret:$("#f_zdoi_appsecret").val(),
				f_zdoi_accessed:$("#f_zdoi_accessed").val()
			};
		}
		
		$(function(){
			new EasyuiDatagrid();
			gotoSearch = function(){
				$("#easyui-datagrid").datagrid('reload',getGueryParams());
			};
			
		});
		
		function SubgridTabOnSelect(title,index){
			setTimeout(function(){
				$("#easyui-datagrid").datagrid('fixDetailRowHeight',index);
			},300);
			setTimeout(function(){
				$("#easyui-datagrid").datagrid('fixDetailRowHeight',index);
			},3000);
	    }
		
		function load(){
			$(".datagrid-row-expander datagrid-row-expand").attr("display","none"); 
		}
		
		function onpress(){
			var event=arguments.callee.caller.arguments[0]||window.event;//消除浏览器差异
	   		  	if (event.keyCode == 13){  
	      			gotoSearch($('#easyui-treegrid'));
	    		}
		}
		
		function edit(id){
			openDialog($("#dlg"),'zjdataitf_update.jsp?f_zdoi_id='+id);
		}

		function add(){
			openDialog($('#dlg'),'zjdataitf_add.jsp');
		}
		
		function info(id){
			openDialog($("#itfDatas"),'zjdataitfDatas_list.jsp?f_zdoi_id='+id);
		}
		
		function batch_delete() {
			var rows = $("#easyui-datagrid").datagrid('getSelections');
			var ids = '';
			if(rows.length <= 0) {
				alert("请至少选择一条记录!");
			} else {
				if(confirm("确认是否删除这些记录？")){
					for(var i=0;i<rows.length;i++) {
						ids += rows[i].f_zdoi_id + ',';
					}
					ids = ids.substring(0, ids.length - 1);
					$.ajax({
						url:"../../industry/batch_delete_zjDataOpenInterface.do?stime=<%=nonceObj[0]%>&sign=<%=nonceObj[1]%>",
						dataType : 'json',
						data : {ids : ids},
						type : 'get',
						success:function(data) {
							alert(data.result);
							gotoSearch($('#easyui-treegrid'));
							window.location.reload();
						}
					});
				}
			}
		}

		
	</script>
</head>
<body onload="load();" style="width: 100%;">
	<input type="hidden" id="sessionId" value="${pageContext.session.id}" />
	<table id="easyui-datagrid" title="浙江数据开放接口列表"></table>
	<div id="toolbar" class="easyui_datagrid_toolbar" style="">
		<div class="easyuiSearch">
			<form onsubmit="return false;" method="post">
				<table cellspacing="0" cellpadding="0" width="90%">
					<tr>
						<td align="left" width="7%">接口名称:</td>
						<td align="left" width="15%"><input name="f_zdoi_name" id="f_zdoi_name" style="width: 150px;" onkeydown="onpress();" /></td>
						<td align="right" width="10%">接口地址:</td>
						<td align="left" width="15%"><input name="f_zdoi_path" id="f_zdoi_path" style="width: 150px;" onkeydown="onpress();" /></td>
						<td align="right" width="7%">接口认证id:</td>
						<td align="left" width="15%"><input name="f_zdoi_appsecret" id="f_zdoi_appsecret" style="width: 250px;" onkeydown="onpress();" /></td>
					</tr>
					<tr>
						<td align="left" width="7%">接口状态:</td>
						<td align="left" width="16%">
							<select id="f_zdoi_status" name="f_zdoi_status">
									<option value="0">请选择</option>
									<option value="1">有效</option>
									<option value="2">无效</option>
							</select>
						</td>
						<td align="right" width="10%">是否可被访问:</td>
						<td align="left" width="16%">
							<select id="f_zdoi_accessed" name="f_zdoi_accessed">
									<option value="0">请选择</option>
									<option value="1">可被访问</option>
									<option value="2">不可被访问</option>
							</select>
						</td>
						<td align="left" width="10%">
							<limits:uiAuth url="zjDataOpenInterface_list.do">
								<a href="javascript:void(0);" class="easyui-linkbutton"
									data-options="iconCls:'icon-search', plain:true"
									onclick="gotoSearch($('#easyui-datagrid'))">查询</a>
							</limits:uiAuth>
							
							<limits:uiAuth url="insert_zjDataOpenInterface.do">
								<a href="javascript:void(0);" class="easyui-linkbutton"
									data-options="iconCls:'icon-add', plain:true" onclick="add()">增加节目</a>
							</limits:uiAuth>
						</td>
		
						<td align="left" width="10%">
							<limits:uiAuth url="stream.jsp">
								<a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0);"
								onclick="batch_delete();">批量删除</a>
							</limits:uiAuth>
						</td>
						
					</tr>
				</table>
			</form>
		</div>
	</div>
	
	<div id="dlg" class="easyui-dialog"
		style="width: 950px; height: 600px; padding-top: 0px;"
		data-options="title:'浙江数据开放接口管理', iconCls:'icon-save',modal:true,closed:true,buttons:'#dlg_buttons'">
		<iframe scrolling="auto" frameborder="0"
			style="width: 100%; height: 99%;"></iframe>
	</div>
	
	<div id="itfDatas" class="easyui-dialog"
		style="width: 950px; height: 600px; padding-top: 0px;"
		data-options="title:'浙江数据开放接口数据详情', iconCls:'icon-save',modal:true,closed:true,buttons:'#dlg_buttons'">
		<iframe scrolling="auto" frameborder="0"
			style="width: 100%; height: 99%;"></iframe>
	</div>
	
	<!-- 弹出框 -->
	<div id="win" class="easyui-window" closed="true" modal="true" iconCls="icon-save" style="width:340px; height: 220px; left: 50%px;top: 30%;" title="接口数据批量导入">
		<input type="hidden" name="f_zdoid_interface_id" val="0"/>
		<div class="easyui-layout" fit="true">
			
			<div region="center" border="true">
				<div>
					<p>
						<font size="6" style="font-weight: bold;color: gray;">批量导入说明:</font><br/>
						&nbsp;&nbsp;1. 请先将模板中的中文字段名改为对应的英文字段名<br/>
						&nbsp;&nbsp;2. 导入文档<br/>
					</p>
				</div>
			</div>
			
			<div region="south" border="false" style="text-align:left;height:40px;padding: 3px">
				<input id="uploadFile2"  type="file" name="file"/>
			</div>
			
		</div>
	</div>
	

<script type="text/javascript">
	$(function(){
		$('#win').window({
	       onBeforeClose:function(){ 
				//window.location.reload();	
	       }
		});
		initFileUpload("#uploadFile2", {});
	});
	
	function batchAddZjDataOpenInterfaceDatas(f_zdoid_interface_id){
		$('#win').window('open');
		$("#win input[name='f_zdoid_interface_id']").val(f_zdoid_interface_id);
	}
	
	function initFileUpload(inputId, params){
		var action = '../../industry/insert_batch_zjDataOpenInterfaceDatas.do?stime=<%=nonceObj[0]%>&sign=<%=nonceObj[1]%>&jsessionid='+$("#sessionId").val();
		$(inputId).uploadify({
			'swf'           :'../../swf/uploadify.swf',
			'uploader'      :action,
			'formData'      :params,
			'fileObjName'   :'uploadify',
			'cancelImg' 	:"../../imgs/uploadify-cancel.png",
			'queueId'		:"fileQueue",
			'fileTypeDesc'  :"Zip File",
			'fileTypeExts'	:"*.zip",//限制文件类型 
			'auto'			:true,//是否自动上传
			'multi'			:false,//是否允许多文件上传
			'buttonText'	:"导入文档",
			'method'		:"POST",
			'onInit'        : function(){
			},
			'onUploadStart' : function(file){
				$(inputId).uploadify('settings','formData', {"f_zdoid_interface_id" : $("#win input[name='f_zdoid_interface_id']").val(),"f_path" : "<%=f_path%>"});
				jQuery.messager.alert('批量导入','批量导入开始, 操作结果请稍后.');
			},
			'onUploadSuccess' : function(file,data,response) {
				if(data != null && data != undefined && data != ''){
					jQuery.messager.alert('批量导入',data);
				}
			},
			'onUploadError' : function(file, errorCode, errorMsg, errorString) {
				if(errorMsg == '302'){
					jQuery.messager.alert('批量导入','批量导入失败，请检查登录状态或者无此权限!');
				}
	        }
		});
	}

</script>
	
</body>
</html>